package com.ljh.consumer.application;
import com.ljh.common.model.User;
import com.ljh.common.service.UserService;
import com.ljh.myrpc.Proxy.ServiceProxyFactory;
import com.ljh.myrpc.RpcApplication;
import com.ljh.myrpc.bootstarp.ConsumerBootStarp;
import com.ljh.myrpc.config.RpcConfig;
import com.ljh.myrpc.utils.ConfigUtils;

public class Consumer {
    /**
     * 简易服务消费者示例
     */

    public static void main(String[] args) {
        /**
         * 简化到ServiceProxyFactory内判断配置文件
         */
        ConsumerBootStarp.init();
        RpcConfig rpcConfig = RpcApplication.getRpcConfig();
        UserService userService;
        if(rpcConfig.isMock()) {
            // 获取Mock代理对象
            userService = ServiceProxyFactory.getMockProxt(UserService.class);
        } else {
            // 获取真实代理对象
            userService = ServiceProxyFactory.getProxy(UserService.class);
        }
        User user = new User();
        user.setName("ljh");
        // 调用
        User newUser = userService.getUser(user);
        if(newUser != null){
            System.out.println(newUser.getName());
        }else{
            System.out.println("user == null");
        }
        long number = userService.getNumber();
        System.out.println(number);
        User user1 = new User();
        user1.setName("ljh1");
        // 调用
        User newUser1 = userService.getUser(user1);
        if(newUser1 != null){
            System.out.println(newUser1.getName());
        }else{
            System.out.println("user1 == null");
        }
    }

}
